package com.sh.rbac.core.security.handler;

import com.sh.rbac.core.common.result.Result;
import com.sh.rbac.core.common.result.ResultCodeEnum;
import com.sh.rbac.core.common.util.WebUtils;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 权限不足处理
 *
 * @since 2024-04-05 22:14
 */
@Component
public class AuthAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        WebUtils.renderString(response, Result.failure(ResultCodeEnum.AUTH_NOT_PERMISSION));
    }
}
